{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "** Option 1: Using the JSONL File **"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "def f(text, wrong, right):\n",
      "    new_text = text.replace(wrong, right)\n",
      "    return new_text.upper()\n",
      "assert f(\"zn kgd jw lnt\", \"h\", \"u\") == 'ZN KGD JW LNT'\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "# First, load the data\n",
    "import json\n",
    "data = [json.loads(l) for l in open(\"data/cruxeval.jsonl\", \"r\").readlines()]\n",
    "\n",
    "# Then, inspect the data\n",
    "id = 15\n",
    "code, input, output = data[id][\"code\"], data[id][\"input\"], data[id][\"output\"]\n",
    "code_to_check = f\"{code}\\nassert f({input}) == {output}\"\n",
    "print(code_to_check)\n",
    "\n",
    "# Finally, check that the input-output pair is correct\n",
    "from evaluation.utils_execute import check_correctness\n",
    "print(check_correctness(code_to_check, timeout=3))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "** Option 2: Using HuggingFace Datasets **"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "def f(text, wrong, right):\n",
      "    new_text = text.replace(wrong, right)\n",
      "    return new_text.upper()\n",
      "assert f(\"zn kgd jw lnt\", \"h\", \"u\") == 'ZN KGD JW LNT'\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "# First, load the data\n",
    "from datasets import load_dataset\n",
    "data = load_dataset(\"cruxeval-org/cruxeval\")[\"test\"]\n",
    "\n",
    "# Then, inspect the data\n",
    "id = 15\n",
    "code, input, output = data[id][\"code\"], data[id][\"input\"], data[id][\"output\"]\n",
    "code_to_check = f\"{code}\\nassert f({input}) == {output}\"\n",
    "print(code_to_check)\n",
    "\n",
    "# Finally, check that the input-output pair is correct\n",
    "from evaluation.utils_execute import check_correctness\n",
    "print(check_correctness(code_to_check, timeout=3))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
